package com.lkj.aspect;

import com.lkj.annotation.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;

import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class LogAspect {

    //配置织入点
    @Pointcut("@annotation(com.lkj.annotation.Log)")
    public void logPointCut(){

    }



    @Before(value = "logPointCut()")
    public void doBefore(){
        System.out.println("输入前。。。");
    }


    @AfterReturning(pointcut = "logPointCut()",returning = "jsonResult")
    public void doAfterReturning(JoinPoint joinPoint,Object jsonResult){

        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature)signature;
        Method method = methodSignature.getMethod();
        if (method != null){
            Log methodAnnotation = method.getAnnotation(Log.class);

            String title = methodAnnotation.title();
            boolean saveRequestData = methodAnnotation.isSaveRequestData();

            System.out.println("title"+title);
            System.out.println("saveRequestData:"+saveRequestData);
        }


        System.out.println("进入切面。。。。");
    }
}
